using UnityEngine;
using System.Collections.Generic;

public class Load : MonoBehaviour {
	
	string[] prefabNames= {"Normal can","PET bottle", "Sardine can", "Tetrabrik"};
	
	// Use this for initialization
	public void LoadLevel () {
		int numTargets = PlayerPrefs.GetInt("NumTargets");
		if(numTargets==0){
			PlayerPrefs.SetInt("NumTargets",3);
			numTargets = 3;
		}
		
		GameObject[] objects = GameObject.FindGameObjectsWithTag("Respawn");
		List<int> indexes = new List<int>();
		List<Vector3> positions = new List<Vector3>();
		for(int i=0;i<objects.Length;i++)
		{
			indexes.Add(i);
		}
		for(int i=0; i<numTargets;i++)
		{
			int randomIndex = Random.Range(0,indexes.Count);
			positions.Add(objects[indexes[randomIndex]].transform.position);
			indexes.Remove(randomIndex);
		}
		
		int iGo=0;
		foreach(Vector3 v in positions)
		{
			int randomIndex = Random.Range(0,prefabNames.Length);
			
			GameObject go = Instantiate(Resources.Load(prefabNames[randomIndex])) as GameObject;
			go.name = prefabNames[randomIndex] +iGo;
			go.transform.position = new Vector3(positions[iGo].x, positions[iGo].y+ 1.2f, positions[iGo].z);
			iGo++;
		}
	}
}
